package h_eekwan.basic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import h_eekwan.interfaces.bookService;

public class JDBCbookdb implements bookService {
	// JDBC 접속 정보
		private static final String DRV = "oracle.jdbc.OracleDriver";
		private static final String URL = "jdbc:oracle:thin:@//localhost:1521/xe"; // 오라클은 1521,mysql은 3306 포트
		private static final String USR = "scott";
		private static final String PWD = "TIGER";
	// SQL 문 작성
		private static final String createSQL =				
				" create table book(id number(5) primary key, title varchar(50), "
				+ " publisher varchar(30), author varchar(30)) ";
		
		@Override
		public boolean addBook() {
			Connection conn = null;
			PreparedStatement ps = null;
			boolean result = true;
			try{
				Class.forName(DRV);
				conn = DriverManager.getConnection(URL, USR, PWD);	
				
				ps = conn.prepareStatement(createSQL);	
				ps.executeUpdate();
				
//				if(cnt>0) result = true;
				
			}catch(Exception ex){
				ex.printStackTrace();				
			} finally{
				if (ps != null)
					try {ps.close();} catch(Exception e){}
				if (conn != null)
					try {conn.close();} catch(Exception e){}
			}
			
			
			return result;
		}
		
		
}
